/*#include <iostream>
#include <unistd.h>
#include <sys/socket.h>
#include <string>
#include <string.h>
#include <netdb.h>
#include <arpa/inet.h>
#define ServerIP 42.194.129.37
#define PORT 8080
#define MAX 80
using namespace std;
*/
#include "ChatClient.h"
//string username;
/*
class user
{
public:



private:
set<string> myfriend;    //好友
deque<map<string,string>> newmsg; //未读消息链表
size_t num;    //未读消息数
vector<map<string,string>> allmsg;  //所有消息
};
*/

//connect to server
void ConnectServer(int &sockfd,struct sockaddr_in servaddr);

//write data to socket and get string
string datadeal(int sockfd,string data);

//log in
int login(int sockf);
/*
void chat()
{
while(1)
{
cout<<"select<<addfriend"<<endl;
cin>>what;
if(select)
while(1){
cout<<all friend>>endl;
cout<<"select who"<<"back"<<endl;;
cin>>who;
if(who is not friend)
break;
cout<<"chatting with xxx...">>endl;
while(1)
{
//thread ,printf from xxx
//打印消息链表中所有who的消息，并存入副本，然后出链表
cin>>message;
//更新本地副本，并上传服务器
//服务器

//接口
cout<<"to xxx:message,time"
if(back) break;
}
}
else if(add friend)
while(1)
{
cout<<"add who"<<"back"<<endl;
cin>>name;
//inmap查看服务器数据
if(inmap)
cout<<"success"<<endl;
else cout<<"user don`t exist"<<endl;
if(back) break;
}

else if(back) break;
else cout<<"try again"<<endl;
}
}
void square()
{
while(1)
{
cout<<"send to square"<<"back"<<endl;
cout<<"all title and user and time"<<endl;
if(send to square)
{
cin>>title;
cin>>body;
//sendtoserver服务器接口
sendtoserver();
cout<<"ok"<<endl;

}
else if("more of n")
cout<<"user title body time"<<endl;
else if(back) break;
else "try again";

}
}
void message()
{
//列出消息链表中所有消息的名字，时间
}
*/
int main()
{
int sockfd,num;
string input;
string sbuff="number";
struct sockaddr_in servaddr;
bzero(&servaddr,sizeof(servaddr));
 //分配IP，端口
 servaddr.sin_family = AF_INET; 
 servaddr.sin_addr.s_addr = inet_addr("42.194.129.37");
 servaddr.sin_port = htons(PORT); 
ConnectServer(sockfd,servaddr);
login(sockfd);
while(1){
//num=datadeal(sockfd,sbuff);
cout<<"chat  post  message"<<num<<"  close"<<endl;
cin>>input;
if(input=="chat"||input=="post"||input=="message"||input=="close")
input=datadeal(sockfd,input);   //发送特定消息
if(input=="chat")
chat(sockfd);
else if(input=="post")
post(sockfd);
//else if(input=="message")
//msg(sockfd);
else if(input=="close")
break;
else cout<<"command not found"<<endl;
}

close(sockfd); 

}
